package cn.com.checne.controller.front;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import cn.com.checne.constants.Constants;
import cn.com.checne.dao.CompanyInfoDao;
import cn.com.checne.model.domain.CompanyInfo;
import cn.com.checne.util.HeaderUtils;
import cn.com.checne.util.LanguageUtils;

@Controller
public class CompanyFrontController {
	protected static final Logger logger = Logger.getLogger(CompanyFrontController.class);

	@Resource
	private CompanyInfoDao companyDao;


	//联系我们
	@RequestMapping(value="/{lg}/contactus",method=RequestMethod.GET)
	public ModelAndView contactus(
			@PathVariable String lg,
			HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
		
		ModelAndView mav = new ModelAndView();
		lg = StringUtils.isBlank(lg) ? Constants.LANGUAGE_CN : lg ;
		String viewName = "front/" + lg + "/company" ;
		int languageId = LanguageUtils.getLanguage(lg);
		
		CompanyInfo company = companyDao.getCompanyInfo(1,languageId);
		
		modelMap.put("company", company);
		modelMap.addAllAttributes(LanguageUtils.getModelMap(lg));
		modelMap.addAllAttributes(HeaderUtils.getHeaderMap(languageId));
		mav.setViewName(viewName);
		mav.addAllObjects(modelMap);
		return mav ;
	}
	
	//关于我们
	@RequestMapping(value="/{lg}/aboutus",method=RequestMethod.GET)
	public ModelAndView aboutus(
			@PathVariable String lg,
			HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
		
		ModelAndView mav = new ModelAndView();
		lg = StringUtils.isBlank(lg) ? Constants.LANGUAGE_CN : lg ;
		String viewName = "front/" + lg + "/company" ;
		int languageId = LanguageUtils.getLanguage(lg);
		
		CompanyInfo company = companyDao.getCompanyInfo(2,languageId);
		
		modelMap.put("company", company);
		modelMap.addAllAttributes(LanguageUtils.getModelMap(lg));
		modelMap.addAllAttributes(HeaderUtils.getHeaderMap(languageId));
		mav.setViewName(viewName);
		mav.addAllObjects(modelMap);
		return mav ;
	}
}